from WebApp import WebApp
from routes.user import user
from routes.admin import admin
from tools.general import get_self_ip
from flask_login import current_user
from flask import redirect


@admin.before_request
def is_login():
    # print('判断是否登录')
    # print('is_authenticated：', current_user.is_authenticated)
    # print('is_active：', current_user.is_active)
    # print('get_id：', current_user.get_id())
    if not current_user.is_authenticated:
        return redirect('/login')


# 注册路由；注意before_request，一定要在注册之前声名，注册之后声名无效
WebApp.register_blueprint(user)
WebApp.register_blueprint(admin)

if '__main__' == __name__:
    # 应用运行
    WebApp.run(get_self_ip(), 8001, debug=False)
